import http from './http'


//获取角色管理的列表数据
const queryRoleList=obj=>{
    let {pageNum=1,pageSize=10,roleName,roleKey,status,beginTime,endTime}=obj;
    let params={
            pageNum,
            pageSize
        }
    if (roleName) params.roleName=roleName
    if (roleKey) params.roleKey=roleKey
    if (status) params.status=status

    let url = '/system/role/list?';
    if(beginTime){
        url+=`${encodeURIComponent(`params[beginTime]`)}=${beginTime}`
    }
    if(endTime){
        url+=`&${encodeURIComponent(`params[endTime]`)}=${endTime}`
    }
    return http.get(url,{params})
}
//改变某个角色的状态
const changeStatus=(roleId, status)=>{
    return http.put('/system/role/changeStatus',{roleId, status})
}





//获取部门树状信息
const queryDeptTree=()=>http.get(`/system/user/deptTree`)

//获取用户列表数据
const queryUserList=obj=>{
    let {pageNum=1,pageSize=10,userName,phonenumber,status,beginTime,endTime}=obj;
    let params={
            pageNum,
            pageSize
    }
    if (userName) params.userName=userName
    if (phonenumber) params.phonenumber=phonenumber
    if (status) params.status=status
    let url=`/system/user/list?`
    if (beginTime) {
        url+=`${encodeURIComponent(`params[beginTime]`)}=${beginTime}`
    }
    if (endTime) {
        url+=`&${encodeURIComponent(`params[endTime]`)}=${endTime}`
    }
    return http.get(url,{params})
}
//改变某个用户的状态
const changeUserStatus=(roleId, status)=>{
    return http.put('/system/user/changeStatus',{roleId,
        status})
}

export default {
    queryRoleList,
    queryDeptTree,
    queryUserList,
    changeStatus,
    changeUserStatus
}